// import { Cloud } from 'laf-client-sdk'

// const cloud = new Cloud({ 
//   baseUrl: "https://as3ji7.lafyun.com",
//   getAccessToken: () => localStorage.getItem('access_token')
// })
import cloud from './cloud'

// regiser function
export async function register(username, password) {
  const res = await cloud.invoke('register', {
    username: username,
    password: password
  })

  return res
}

// login function
export async function login(username, password) {
  const res = await cloud.invoke('login', {
    username: username,
    password: password
  })

  if(res.access_token) {
    // save token
    localStorage.setItem('access_token', res.access_token)
  }
  return res
}

// 列表
export async function list(data) {
  const res = await cloud.invoke('user',data)
  return res
}
// 添加
export async function create(data) {
  const res = await cloud.invoke('user_create',data)
  return res
}
// 修改
export async function update(data) {
  const res = await cloud.invoke('user_edit',data)
  return res
}
// 删除
export async function remove(data) {
  const res = await cloud.invoke('user_delete',data)
  return res
}